package com.tomorrow.runner.util;

import com.amap.api.maps2d.AMapUtils;
import com.amap.api.maps2d.model.LatLng;

import cn.sucun.android.log.Log;

/**
 * 经纬度与米转换
 * Created by tomorrow on 16-4-30.
 */
public class LatLngUtil {
    private static double LatPerMeter;
    private static double LngPerMeter;
    public synchronized static LatLng latLngOffsetByMeter(LatLng point,double xoffset,double yoffset){
        computeMeter(point);
        double lat = xoffset * LatPerMeter;
        double lng = yoffset * LngPerMeter;
        return new LatLng(point.latitude + lat,point.longitude + lng);
    }

    public static double distanceBetween(LatLng point1,LatLng point2){
        return AMapUtils.calculateLineDistance(point1,point2);
    }
    private static void computeMeter(LatLng point){
        LatLng point2 = new LatLng(point.latitude+1,point.longitude);
        LatLng point3 = new LatLng(point.latitude,point.longitude+1);
        double distance1 = distanceBetween(point,point2);
        double distance2 = distanceBetween(point,point3);
        LatPerMeter = 1.0 / distance1;//纬度每米
        Log.i("LatLngUtil","LatPerMeter="+ LatPerMeter);
        LngPerMeter = 1.0 / distance2;//经度每米
        Log.i("LatLngUtil","LngPerMeter="+ LngPerMeter);
    }
}
